package com.timoon.component.panel.jqgrid.action;

import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.markup.html.form.Form;

import com.googlecode.wicket.jquery.ui.form.button.AjaxButton;
import com.timoon.component.panel.jqgrid.JqGridPanel;
import com.timoon.component.panel.jqgrid.panel.CreatorPanel;

public class ModifierButton extends RecordIdsReceiverAjaxButton {
	private static final long serialVersionUID = -8768081847336873991L;
	private static String WIN_TITLE_OF_CONFIG_MAP_KEY="8768081847336873991_mofidier_button";

	private ModalWindow win;
	
	private JqGridPanel mainPanel;
	
	public ModifierButton(String id,JqGridPanel mainPanel) {
		super(id,mainPanel);
		// TODO Auto-generated constructor stub
		if(!mainPanel.isButtonVisible(JqGridPanel.MODIFIER_BUTTON_ENABLE)){
			this.setVisible(false);
		}
		
		
		this.win=mainPanel.getWin();
		this.mainPanel=mainPanel;
	}
	/**
	 * 向mainPanel索取编辑面板
	 * @param id
	 * @param mainPanel
	 * @return
	 */
	private CreatorPanel getCreatorPanel(String id,JqGridPanel mainPanel,String recordId){
		return mainPanel.getCreatorPanel(id, mainPanel,recordId);
	}
	@Override
	protected void onReceivedRecordId(String recordId, AjaxRequestTarget target) {
		// TODO Auto-generated method stub
		CreatorPanel creatorPanel=this.getCreatorPanel(win.getContentId(),mainPanel,recordId);
		if(creatorPanel!=null){
			win.setTitle(mainPanel.getConfigByKey(WIN_TITLE_OF_CONFIG_MAP_KEY));
			win.setMinimalHeight(700);
			win.setMinimalWidth(400);
			win.setCssClassName(ModalWindow.CSS_CLASS_GRAY);
			win.setContent(creatorPanel);
			win.show(target);
		}
	}

}
